package com.yjhealth.libs.core.data;

import android.support.annotation.IntDef;
import android.support.annotation.Nullable;

import com.yjhealth.libs.core.core.CoreVo;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * Created on 2019/5/29 16:08
 *
 * @author cyf
 * @des : living data 数据类
 */


public class DataRes<T> extends CoreVo {
    @Status private int status;
    @Nullable private T data;
    @Nullable private String code;
    @Nullable private String message;
    
    private DataRes(@Status int status, @Nullable T data, @Nullable String code,
                    @Nullable String message) {
        this.status = status;
        this.code = code;
        this.data = data;
        this.message = message;
    }

    public static <T> DataRes<T> success(T data) {
        return new DataRes<>(SUCCESS, data, null, null);
    }

    public static <T> DataRes<T> error(T data, String code, String msg) {
        return new DataRes<>(ERROR, data, code, msg);
    }
    public static <T> DataRes<T> error(String code, String msg) {
        return error(null, code, msg);
    }

    public static <T> DataRes<T> prepare() {
        return new DataRes<>(PREPARE, null, null, null);
    }


    public static final int SUCCESS = 1;
    public static final int ERROR = 2;
    public static final int PREPARE = 3;
//    public static final int RUNNING = 4;
//    public static final int COMPLETE = 5;
    @Retention(RetentionPolicy.SOURCE)
    @IntDef({SUCCESS, ERROR, PREPARE})
    @interface Status {
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    @Nullable
    public T getData() {
        return data;
    }

    public void setData(@Nullable T data) {
        this.data = data;
    }

    @Nullable
    public String getCode() {
        return code;
    }

    public void setCode(@Nullable String code) {
        this.code = code;
    }

    @Nullable
    public String getMessage() {
        return message;
    }

    public void setMessage(@Nullable String message) {
        this.message = message;
    }
    
    public boolean isSuccess(){
        return SUCCESS == status;
    }
    public boolean isError(){
        return ERROR == status;
    }
    public boolean isPrepare(){
        return PREPARE == status;
    }
}
